<?php
/**
 * Created by zengxianfen on 2020/7/20 15:22.
 */

namespace App\Model\Manager;


use App\Exception\ServiceException;
use App\Model\Service\CompanyService;
use App\Model\Service\SMSService;
use Hyperf\Di\Annotation\Inject;

class RegisterManager
{

    /**
     * @Inject()
     * @var SMSService
     */
    protected $SMSService;

    /**
     * @Inject()
     * @var CompanyService
     */
    protected $companyService;


    /**
     * @author zengxianfen 2020/7/20
     * @param array $params
     * @return bool
     * @throws ServiceException
     */
    public function registerCompany(array $params) {
        //校验手机验证码是否存在并通过验证
        $this->SMSService->checkCode($params['code_key'],$params['phone'],$params['code']);
        //确认公司名称是否重复
        $this->companyService->checkCompanyExisted($params['name']);
        //插入公司表/用户表数据
        $this->companyService->createCompanyAndUser($params);
        return true;
    }
}